<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mr_ortuwali extends CI_Controller {

	function __construct() {
        parent::__construct();	
        $this->isLogin();
		$this->load->model("master/master_ortuwali");
		$this->load->model("master/master_pekerjaan");
		$this->load->model("master/master_gaji");
		$this->load->model("master/master_pendidikan");
		$this->load->model("master/master_agama");
	}

	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}

	function add_exe()
	{		
		$hubungan=$this->input->post('hubungan');
		if($hubungan <> 'Wali'){
			$hub_wali = "Tidak Ada";			
		}else{
			$hub_wali = $this->input->post('hub_wali');
		}
		
		$dataInsert = array(
			'nis' => $this->input->post('nis'),
			'hubungan' => $this->input->post('hubungan'),
			'hub_wali' => $hub_wali,
			'nama' => $this->input->post('nama'),
			'alamat' => $this->input->post('alamat'),
			'kel' => $this->input->post('kel'),
			'kec' => $this->input->post('kec'),
			'tlp' => $this->input->post('tlp'),
			'email' => $this->input->post('email'),
			'id_mr_pekerjaan' => $this->input->post('id_mr_pekerjaan'),
			'jabatan' => $this->input->post('jabatan'),
			'id_mr_gaji' => $this->input->post('id_mr_gaji'),
			'kantor' => $this->input->post('kantor'),
			'alamat_kantor' => $this->input->post('alamat_kantor'),
			'tlp_kantor' => $this->input->post('tlp_kantor'),
			'fax_kantor' => $this->input->post('fax_kantor'),
			'id_mr_pendidikan' => $this->input->post('id_mr_pendidikan'),
			'warga' => $this->input->post('warga'),
			'id_mr_agama' => $this->input->post('id_mr_agama')
		);
		$this->master_ortuwali->add($dataInsert);		
		$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
		redirect ($back);
	}
	
	function edit()
	{
		$id_mr_ortuwali = $this->input->post('id_mr_ortuwali');
		$data['list']=$this->master_ortuwali->edit($id_mr_ortuwali);
		$data['list_pekerjaan']=$this->master_pekerjaan->read();
		$data['list_gaji']=$this->master_gaji->read();
		$data['list_pendidikan']=$this->master_pendidikan->read();
		$data['list_agama']=$this->master_agama->read();
		$this->load->view('master/mr_ortuwali/edit',$data);
	}
	
	function update()
	{		
		$id_mr_ortuwali=$this->input->post('id_mr_ortuwali');
		$hubungan=$this->input->post('hubungan');
		if($hubungan <> 'Wali'){
			$hub_wali = "Tidak Ada";			
		}else{
			$hub_wali = $this->input->post('hub_wali');
		}
		$dataUpdate = array(
			'hubungan' => $this->input->post('hubungan'),
			'hub_wali' => $hub_wali,
			'nama' => $this->input->post('nama'),
			'alamat' => $this->input->post('alamat'),
			'kel' => $this->input->post('kel'),
			'kec' => $this->input->post('kec'),
			'tlp' => $this->input->post('tlp'),
			'email' => $this->input->post('email'),
			'id_mr_pekerjaan' => $this->input->post('id_mr_pekerjaan'),
			'jabatan' => $this->input->post('jabatan'),
			'id_mr_gaji' => $this->input->post('id_mr_gaji'),
			'kantor' => $this->input->post('kantor'),
			'alamat_kantor' => $this->input->post('alamat_kantor'),
			'tlp_kantor' => $this->input->post('tlp_kantor'),
			'fax_kantor' => $this->input->post('fax_kantor'),
			'id_mr_pendidikan' => $this->input->post('id_mr_pendidikan'),
			'warga' => $this->input->post('warga'),
			'id_mr_agama' => $this->input->post('id_mr_agama')
		);
		$this->master_ortuwali->update($id_mr_ortuwali,$dataUpdate);		
		$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
		redirect ($back);
	}
	
	function delete()
	{
		$id_mr_ortuwali = $this->security->xss_clean($this->uri->segment(3));
		$this->master_ortuwali->delete($id_mr_ortuwali);
		$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
		redirect ($back);
	}
	
}